var exec = require('child_process').exec;
var path = require('path');

var that = {};

var execPythonScript = function(pythonScriptName, args, pythonVersion, callback) {

  // 默认python2.7
  var pythonVersion = pythonVersion || 'python2.7';

  // 执行脚本
  var pythonScriptPath = path.resolve(__dirname, '../../quant/webScript', pythonScriptName);

  // 默认不传参数
  var args = args || [];
  var execStr = [pythonVersion, pythonScriptPath, args.join(' ')].join(' ');

  exec(execStr, function(err, stdout, stderr) {

    if (err) {
      console.log('err', err);
    } else {
      callback && callback(stdout);
    };
  });
};

that.execPythonScript = execPythonScript;
module.exports = that;
